//
//  OrderParticularsViewController.m
//  LogisticsFollow
//
//  Created by Faith on 2017/1/22.
//  Copyright © 2017年 manridy. All rights reserved.
//

#import "OrderParticularsViewController.h"
#import "OrderParticularsTableViewCell.h"

@interface OrderParticularsViewController () < UITableViewDelegate , UITableViewDataSource >

@property (nonatomic ,weak) UITableView *tableView;

@end

@implementation OrderParticularsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tableView.backgroundColor = kRGBA(245, 246, 246, 1);
    self.navigationItem.title = @"订单详情";
    self.view.backgroundColor = kRGBA(245, 246, 246, 1);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDelegate && UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    OrderParticularsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderParticularsCell"];
    
    if (self.model) {
        cell.model = self.model;
    }
    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:XXF_CGRectMake(0, 0, kControllerWidth, 75)];
    view.backgroundColor = kRGBA(245, 246, 246, 1);
    UILabel *orderNote = [[UILabel alloc] initWithFrame:XXF_CGRectMake(16.5, 10, kControllerWidth - 33, view.frame.size.height - 20)];
    [orderNote setFont:[UIFont systemFontOfSize:14]];
    [orderNote setNumberOfLines:0];
    orderNote.text = [NSString stringWithFormat:@"订单备注：%@",self.model.comments];
    [view addSubview:orderNote];
    
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 591;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 75;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat sectionHeaderHeight = 75;
    if (scrollView.contentOffset.y >= sectionHeaderHeight)
    {
        scrollView.contentInset = UIEdgeInsetsMake(0, 0, -sectionHeaderHeight, 0);
    }
    else if (scrollView.contentOffset.y >= sectionHeaderHeight&&(scrollView.contentOffset.y >= scrollView.contentSize.height))
    {
        scrollView.contentInset = UIEdgeInsetsMake(0, 0, -scrollView.contentOffset.y, 0);
    }
}

#pragma mark - 懒加载
- (UITableView *)tableView
{
    if (!_tableView) {
        UITableView *view = [[UITableView alloc] initWithFrame:XXF_CGRectMake(0, 64, kControllerWidth, kControllerHeight + 64) style:UITableViewStylePlain];
        view.delegate = self;
        view.dataSource = self;
        [view registerNib:[UINib nibWithNibName:@"OrderParticularsTableViewCell" bundle:nil] forCellReuseIdentifier:@"OrderParticularsCell"];
        view.separatorStyle = UIAccessibilityTraitNone;
        view.allowsSelection = NO;
        
        [self.view addSubview:view];
        _tableView = view;
    }
    
    return _tableView;
}

@end
